import WineTraverse as tw
import time
import os
from WineTraverse import util


if __name__=="__main__":
    time.sleep(5)
    wkDir=os.path.dirname(os.path.abspath(__file__))
    print("workdir is "+wkDir)
    resultDir=os.path.join(wkDir,"result","")
    print("work result dir is "+resultDir)
    util.mkdirIfNotExits(resultDir)
    resultLog=os.path.join(resultDir,"result.log")
    util.touchIfNotExits(resultLog)
    print("work result log is "+resultLog)

    resultFile=os.path.join(resultDir,"result.txt")
    util.touchIfNotExits(resultFile)
    print("work result file is "+resultFile)

    f=open(resultLog,"w+")
    f.write(util.getContent("workdir",wkDir))
    f.write(util.getContent("work result dir",resultDir))
    f.write(util.getContent("work result log",resultLog))
    f.write(util.getContent("work result file",resultFile))
        
  
    initImage=os.path.join(resultDir,"init.png")
    print("init png "+initImage)
    x,y,w,h=util.get_active_window_rect()
    print(x,y,w,h)
    util.screenshot((x,y,w,h),initImage,True)
    f.write(util.getContent("screenshot init image",initImage))
    initOcrStr=util.ocrImage(initImage)
    f.write(util.getContent("get init ocr image content",initOcrStr))


    pos=[x,y,w,h]
    # resF=open(resultFile,"w")
    # tw.NewServer(initOcrStr,resultDir,f,resF,pos)
    tw.NewServer(initOcrStr,resultDir,f,resultFile,pos)
    f.close()
    resF.close()
